#include <osgViewer/Viewer>
#include <osg/Node>
#include <osg/Geode>
#include <osg/Group>
#include <osgDB/ReadFile>
#include <osgDB/WriteFile>
#include <osgUtil/Optimizer>
#include <osgViewer/ViewerEventHandlers> //事件监听
#include <osgGA/StateSetManipulator> //事件响应类，对渲染状态进行控制
#include <string>
#include <iostream>
#include <osgDB/ConvertUTF>
#include "template/util.h"
#ifdef _WIN32
#include <Windows.h>
#endif
using namespace std;

int main(int argc, char** argv)
{
	// 解决输出时中文乱码问题
#ifdef _WIN32
	SetConsoleOutputCP(CP_UTF8);
#else
	setlocale(LC_ALL, "en_US.UTF-8");
#endif // _WIN32

	osg::ArgumentParser arguments(&argc, argv);
	osg::ApplicationUsage* usage = arguments.getApplicationUsage();
	usage->setDescription(arguments.getApplicationName() + ",xxxx.");
	usage->setCommandLineUsage("test.exe -i xx -o xx");
	usage->addCommandLineOption("-i <input>", "test input");
	usage->addCommandLineOption("-o <output>", "test output");
	usage->addCommandLineOption("-h or --help", "Display command line parameters");

	// if user request help write it out to cout.
	if (arguments.read("-h") || arguments.read("--help"))
	{
		usage->write(std::cout);
		return 1;
	}

	std::string input, output;
	while (arguments.read("-i", input));
	while (arguments.read("-o", output));

	// 解决输入时中文乱码问题
#ifndef NDEBUG
#else
	input = osgDB::convertStringFromCurrentCodePageToUTF8(input.c_str());
	output = osgDB::convertStringFromCurrentCodePageToUTF8(output.c_str());
#endif // !NDEBUG

	osg::ref_ptr<osg::Image> image = osgDB::readImageFile(R"(test.jpg)");
	previewImage(image);

	return 0;
}
